#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QObject>

#include "mainqmlclass.h"

int main(int argc, char *argv[])
{
    //qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif

    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;
    const QUrl url(QStringLiteral("qrc:/main.qml"));
    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                     &app, [url](QObject *obj, const QUrl &objUrl) {
        if (!obj && url == objUrl)
            QCoreApplication::exit(-1);
    }, Qt::QueuedConnection);
    engine.load(url);

    QObject *rootObject = engine.rootObjects().first();

    QObject *text_input_01_item = rootObject->findChild<QObject*>("textBox1");
    QObject *labelQml = rootObject->findChild<QObject*>("cpp label");
    QVariant ret;
    QMetaObject::invokeMethod(labelQml, "getText", Q_RETURN_ARG(QVariant, ret));
    qDebug() << ret.toString();

//    QMetaObject::inv
//    QMetaObject::invokeMethod(text_input_01_item, "getText", Q_RETURN_ARG(QVariant, ret));
//    qDebug() << ret.toString();

    TextDemo text_demo_;

//    QObject::connect(text_input_01_item, SIGNAL(textChanged(QString)), [](QString newText) {
//          qDebug() << "Text changed:" << newText;
//      });

    QObject::connect(text_input_01_item, SIGNAL(textChanged(Qstring)), &text_demo_, SLOT(print_string()));

    return app.exec();
}
